package GoftIclass

import (
	"github.com/gin-gonic/gin"
	"wskyygyso/casually/GoftModel"
	"wskyygyso/casually/goft"
)

type UserClass struct {
	Db  *goft.GormAdapter
	Age *goft.Value `config:"user.age"`
}

func NewUserClass() *UserClass {
	return &UserClass{}
}

func (u *UserClass) Test(ctx *gin.Context) string {
	return "你是sb"
}

func (u *UserClass) UserDetail(ctx *gin.Context) goft.Model {
	user := GoftModel.NewUserModel()
	err := ctx.ShouldBindUri(user)
	if err != nil {
		goft.Error(err)
	}
	err = u.Db.Table("users").Where("id=?", user.Id).First(&user).Error
	if err != nil {
		goft.Error(err, "没有该用户")
	}
	return user
}

func (u *UserClass) Bind(goft *goft.Goft) {
	goft.Handle("GET", "/test", u.Test)
	goft.Handle("GET", "/user/:id", u.UserDetail)
}
